/**
 * Created by apple on 16/4/6.
 */

/*
 |--------------------------------------------------------------------------
 | 加载 pages 目录下的 html / js 文件, 并缓存在对象中
 |--------------------------------------------------------------------------
 */
let TPL      = {};
let template = require.context('./pages', true, /\.view.html$/);
let ctrl_src = require.context('./pages', true, /\.controller.js$/);

template.keys().forEach(key => {
    TPL[ key ] = template(key)
})

/*
 |--------------------------------------------------------------------------
 | 路由表
 | 使用了 ui-router 详情访问 https://github.com/angular-ui/ui-router/wiki
 |--------------------------------------------------------------------------
 */
export default function routes ($stateProvider, $urlRouterProvider, $locationProvider) {
    "ngInject"
    // 失败路由时的默认跳转
    $urlRouterProvider.otherwise('/');

    $stateProvider
        .state('/', {
            url  : '/',
            views: {
                "post": {
                    templateUrl : TPL[ './post/post.view.html' ],
                    controller  : ctrl_src('./post/post.controller.js').default,
                    controllerAs: "vm"
                }
            }
        })
        .state('home', {
            url         : "/home",
            templateUrl : TPL[ './home/home.view.html' ],
            controller  : ctrl_src('./home/home.controller.js').default,
            controllerAs: "vm"
        })
}